package com.credit.xzgl.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.credit.common.core.domain.entity.SysDictData;
import com.credit.common.core.domain.entity.SysUser;
import com.credit.common.utils.DictUtils;
import com.credit.common.utils.StringUtils;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.credit.common.annotation.Log;
import com.credit.common.core.controller.BaseController;
import com.credit.common.core.domain.AjaxResult;
import com.credit.common.enums.BusinessType;
import com.credit.xzgl.domain.CreditJdjc;
import com.credit.xzgl.service.ICreditJdjcService;
import com.credit.common.utils.poi.ExcelUtil;
import com.credit.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 监督检查Controller
 * 
 * @author credit
 * @date 2025-03-22
 */
@RestController
@RequestMapping("/credit-new/xzgl/creditJdjc")
public class CreditJdjcController extends BaseController
{
    @Autowired
    private ICreditJdjcService creditJdjcService;
    /**
     * 查询监督检查列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CreditJdjc creditJdjc)
    {
        startPage();
        List<CreditJdjc> list = creditJdjcService.selectCreditJdjcList(creditJdjc);
        return getDataTable2(list);
    }

    /**
     * 导出监督检查列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, CreditJdjc creditJdjc)
    {
        List<CreditJdjc> list = creditJdjcService.selectCreditJdjcList(creditJdjc);
        ExcelUtil<CreditJdjc> util = new ExcelUtil<CreditJdjc>(CreditJdjc.class);
        util.exportExcel(response, list, "监督检查数据");
    }

    /**
     * 下载监督检查导入模版
     */
    @RequestMapping("/downloadImportMB")
    public void downloadImportMB(HttpServletResponse response)
    {
        List<CreditJdjc> list = new ArrayList<>();
        ExcelUtil<CreditJdjc> util = new ExcelUtil<CreditJdjc>(CreditJdjc.class);
        util.exportExcel(response, list, "监督检查数据");
    }

    /**
     * 下载监督检查导入模版
     */
    @RequestMapping("/importData")
    public AjaxResult importData(MultipartFile excelfile) throws Exception
    {
        ExcelUtil<CreditJdjc> util = new ExcelUtil<>(CreditJdjc.class);
        List<CreditJdjc> jdjcList = util.importExcel(excelfile.getInputStream());
        String message = creditJdjcService.importData(jdjcList);
        return success2(message);
    }

    /**
     * 获取监督检查详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success2(creditJdjcService.selectCreditJdjcById(id));
    }

    /**
     * 新增监督检查
     */
    @PostMapping
    public AjaxResult add(@RequestBody CreditJdjc creditJdjc)
    {
        return toAjax2(creditJdjcService.insertCreditJdjc(creditJdjc));
    }

    /**
     * 修改监督检查
     */
    @PutMapping
    public AjaxResult edit(@RequestBody  CreditJdjc creditJdjc)
    {
        return toAjax2(creditJdjcService.updateCreditJdjc(creditJdjc));
    }

    /**
     * 删除监督检查
     */
	@RequestMapping("/delete")
    public AjaxResult remove(@RequestParam(value = "ids", defaultValue = "", required = true) String id)
    {
        if(StringUtils.isNotEmpty(id)){
            String[] ids = id.split(",");
            return toAjax2(creditJdjcService.deleteCreditJdjcByIds(ids));
        }
        return toAjax2(0);

    }

    /**
     * 根据字典类型查询字典数据信息
     */
    @PostMapping(value = "/dictType/{dictType}")
    public AjaxResult dictType(@PathVariable String dictType)
    {
        List<SysDictData> data = DictUtils.getDictCache(dictType);
        return success2(data);
    }
    /**
     * 根据字典类型查询字典数据信息
     */
    @PostMapping(value = "/dictTypeAll/{dictType}")
    public AjaxResult dictTypeAll(@PathVariable String dictType)
    {
        Map<String,Object> res = new HashMap<>();
        String[] dictt = dictType.split(",");
        for(String dictty :dictt){
            res.put(dictty,DictUtils.getDictCache(dictty));
        }
        return success2(res);
    }



}
